package DataBase;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Vector;

public class GetItems {
	
	private String suppId;
	
	public GetItems(String sid)
	{
		this.suppId=sid;
	}

	
	public Vector<Vector> getSupItems()
	{
		Vector<Vector> supItems=new Vector<Vector>();
		
     SQLConnection sc=new SQLConnection();
		
		
		try {
			
		PreparedStatement ps = sc.getConnection().prepareStatement("SELECT i.iid,i.Iname,si.suppItemPrice FROM  supplier_item si,item i WHERE si.suppid=? AND si.iid=i.iid;");	
        ps.setString(1,suppId);
		ResultSet rs=ps.executeQuery();	

		ResultSetMetaData rsmd = rs.getMetaData();
		
		 while(rs.next())
	        {   

			 Vector<String>  row = new Vector<String>();
	         for(int col = 1; col <= rsmd.getColumnCount(); col++) 
	         	{                      	                	               
	                 row.add(rs.getString(col));	               
	         	}//for
	         supItems.add(row);
	        }//while
		    ps.close();
			rs.close();
			
		
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		return supItems;
	}
	
	
	
	
	
	public Vector<Vector> getAllItems()
	{
		Vector<Vector> supItems=new Vector<Vector>();
		
SQLConnection sc=new SQLConnection();
		
		
		try {
			
			
			
		PreparedStatement ps = sc.getConnection().prepareStatement("SELECT i.iid ,i.Iname FROM item i WHERE i.iid NOT in (SELECT si.iid FROM  supplier_item si WHERE si.suppid=?);");	
        ps.setString(1,suppId);
		ResultSet rs=ps.executeQuery();	

		ResultSetMetaData rsmd = rs.getMetaData();
		
		 while(rs.next())
	        {   

			 Vector<String>  row = new Vector<String>();
	         for(int col = 1; col <= rsmd.getColumnCount(); col++) 
	         	{                      	                	               
	                 row.add(rs.getString(col));	               
	         	}//for
	         supItems.add(row);
	        }//while
		 ps.close();
		 rs.close();
		 sc.getConnection().close();
		
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
				
		return supItems;
	}
	
}
